package com.neusoft.demo12;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class TestJdbcDemo {
    public static void main(String[] args) {
        JdbcDemo jdbcDemo = new JdbcDemo();
        try {
            //连接数据库
            jdbcDemo.getConnection();
            //调用dml方法，向数据库添加一条数据
            int isRight = jdbcDemo.
                    dml("insert into student(sname,age) values ('XXX',10)");
            System.out.println(isRight);
            //调用query方法查询
        //            ResultSet rs = jdbcDemo.query("select * from student");
        //            //遍历结果集
        //            while(rs.next()) {
        //                //获取当前行的第一列的值
        //                int sno = rs.getInt("sno");
        //                //获取当前行的第二列的值
        //                String name = rs.getString("sname");
        //                //获取当前行的第三列的值
        //                int age = rs.getInt("age");
        //                //输出结果
        //                System.out.println(sno+" "+name+" "+age);
        //            }

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
